/**
 * @author 陈泰来
 * @version V1.0
 * @Project echo-java-base
 * @Title 鸭子观察者
 * @Description *
 * @Package designmodel.composite.observer
 * @date 2021/3/3 10:07 上午
 * @Copyright:学如逆水行舟，不进则退 .
 */
package designmodel.composite.observer;


import java.util.ArrayList;

public class Observable implements QuackObservable {

    //组合观察者集合
    ArrayList<Observer> observables = new ArrayList<>();

    //组合鸭叫辅助接口
    QuackObservable duck;

    //构造
    public Observable(QuackObservable duck) {
        this.duck = duck;
    }

    @Override
    public void registerObserver(Observer observer) {
        observables.add(observer);
    }

    @Override
    public void notifyObservers() {
        for (Observer observer : observables) {
            observer.update(duck);
        }
    }
}
